home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / src_d2.zoo / bash-d2.zoo / libgcc / close.c next >
Encoding:
C/C++ Source or Header  |  1991-09-03  |  1.1 KB  |  56 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  */
  6. #include    <osbind.h>
  7. #include    <fcntl.h>
  8. #include    <device.h>
  9. #include    <stdlib.h>
  10.  
  11. #ifdef DEBUG
  12. #include <stdio.h>
  13. #endif
  14.  
  15. int close(fd)
  16.     int    fd;
  17. {       int     oldfd;
  18.     extern    int    errno;
  19.     int        rval;
  20.     struct _device    *dev;
  21.  
  22.     if ((dev = _dev_fd(fd)) && dev->close)
  23.         return (*dev->close)(fd);
  24.         oldfd=fd;
  25.     fd = __OPEN_INDEX(fd);
  26.     if ((fd >= 0) && (fd < __NHANDLES))
  27.     { if (__open_stat[fd].pipe)
  28.             { rval = pipeclose(oldfd);
  29.               return(rval);
  30.             }
  31.           else 
  32.         if((__open_stat[fd].status == FH_ISAFILE) &&
  33.            (__open_stat[fd].filename))
  34.             free(__open_stat[fd].filename);
  35.         __open_stat[fd].status = FH_UNKNOWN;
  36.         __open_stat[fd].append = 0;
  37.         __open_stat[fd].nodelay = 0;
  38.             __open_stat[fd].pipe = 0;
  39.         __open_stat[fd].eclose = 0;
  40.         __open_stat[fd].filename = (char *) 0;
  41.     }
  42.  
  43.     if ((rval = Fclose(oldfd)) < 0) {
  44.         errno = -rval;
  45.         rval = -1;
  46.     }
  47.  
  48.  
  49. #ifdef DEBUG
  50.     fprintf(stderr, "close(%d)->%d\n", (fd + __SMALLEST_VALID_HANDLE),
  51.          rval);
  52. #endif
  53.     return rval;
  54. }
  55.  
  56.